<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="full-screen" content="yes">
    <meta name="x5-fullscreen" content="true">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
    <link rel="stylesheet" href="../../css/base.css">
    <link rel="stylesheet" href="../../css/icon-font.css"/><!--图标-->
    <link rel="stylesheet" href="../../css/info-list.css"/><!--资讯列表-->
    <link rel="stylesheet" href="../../plugin/mescroll/css/mescroll.min.css">

    <title>专题详情</title>
    <style>

        .topic-detail-wrap {
            background: rgba(255, 255, 255, 1);
            border-radius:.16rem .16rem 0 0;
        }

        .placeholder-top {
            background: rgba(255, 255, 255, 0);
            z-index: 1;
        }

        .topic-detail-head {
            height: 3.92rem;
            width: 7.5rem;
        }

        .topic-detail-img {
            min-height: 4.36rem;
        }

        .topic-detail-img img {
            width: 100%;
            height: 4.36rem;
        }

        .topic-detail-bg {
            top: 0;
            left: 0;
            width: 100%;
            height: 4.36rem;
            background-color: rgba(0, 0, 0, 0.5);
        }

        .topic-detail-info {
            width: 100%;
            top: 1.74rem;
            left: 0;
            padding: 0 .32rem;
        }

        .topic-detail-title {
            line-height: .56rem;
            height: .56rem;
            color:rgba(255,255,255,1);
        }

        .topic-detail-count {
            line-height: .34rem;
            height: .58rem;
            width: 100%;
            padding: 0.08rem 0 0.16rem 0;
            border-bottom: 1px solid rgba(255,255,255,0.29);
            color: rgba(255, 255, 255, 0.6);
        }

        .topic-detail-count span {
            color: white;
        }

        .topic-detail-desc {
            margin-top: 0.16rem;
            color: #FFFFFF;
            max-width: 5.6rem;
        }

        .topic-detail-btn {
            margin-top: 0.16rem;
            color: #FF9523;
        }

        .mescroll-upwarp {
            min-height: 0;
            padding: 0;
        }

    </style>
</head>
<body>

<div class="flex-column h-100-p ff400">
    <!--状态栏-->
    <div class="placeholder-top pos-f">
        <!--状态栏-->
        <div class="status-bar pos-f"></div>
        <!--标题栏-->
        <div class="nav-bar pos-f flex-row justify-content-between c-white align-items-center">
            <div class="left-bar" onclick="clickBack()" style="color: #FFFFFF;">
                <span class="iconfont iconfanhui1 fs16"></span>
            </div>
            <div class="center-bar fs16 ff500 line1"></div>
            <div class="right-bar">
            </div>
        </div>
    </div>

    <div class="mescroll"  id="mescroll">
        <div class="topic-detail-head pos-r">
            <div class="topic-detail-img"><img src="" alt=""></div>
            <div class="topic-detail-bg pos-a"></div>
            <div class="flex-column topic-detail-info pos-a">
                <div class="topic-detail-title fs20 ff500 line1"></div>
                <div class="topic-detail-count fs12"></div>
                <div class="flex-row fs12">
                    <div class="topic-detail-desc line1"></div>
                    <div class="topic-detail-btn"></div>
                </div>
            </div>
        </div>

        <div class="pos-r ">
            <div class="topic-detail-wrap"></div>
        </div>
    </div>
</div>


</body>
<!--这四个文件的引入必须按照顺序-->
<script src="../../js/dict.js"></script>
<script src="../../js/jquery-3.4.1.min.js"></script>
<script src="../../js/checkJsBridge.js"></script>
<script src="../../js/utils.js"></script>
<script src="../../js/api.js"></script>
<!--这四个文件的引入必须按照顺序-->
<script src="../../js/date.js"></script>
<script src="../../js/icon-font.js"></script><!--用于彩色字体图标-->
<script src="../../js/template.js"></script>

<script src="../../js/protobuf.min.js"></script>
<script src="../../js/proto.js"></script>

<script src="../../plugin/mescroll/js/mescroll.min.js"></script>

<script>
  let pm = {
    lastDttm: DateUtils.getNowInt(),
    pageNum: 1,
    pageSize: 10,
    isScroll: true,
    title: '',
    stockList:[]
  }

  function initPage(params) {
    //状态栏自适应
    Utils.sbhAdaptive()

    pm.funcCode = params.funcCode
    pm.infoId = params.infoId
    pm.infoType = params.infoType

    pageScroll()

    //下拉刷新、滚动加载
    meScroll = Template.createMeScroll({
      id: 'mescroll', //区域ID
      pageNum: pm.pageNum,
      downCallback: refreshAchive, //下拉刷新入口
      upCallback: getInfoListByFuncCode //滚动加载入口
    })

  }

  function  reLoadPage() {
    refreshAchive()
  }

  function refreshAchive() {
    pm.isScroll = false//初始化滚动状态
    pm.pageNum = 1
    pm.lastDttm = DateUtils.getNowInt()
    pm.title = ''

    getTopicInfo(true)
    getInfoListByFuncCode()
  }

  function getTopicInfo() {
    // 获取专题详情
    Server.topicDetail.selectFuncInfoByFuncCode({
      funcCode: pm.funcCode
    }).then(function (data) {

      pm.title = data.body.funcName
      $('.topic-detail-img img').attr('src', data.body.coverImgUrl)
      $('.topic-detail-title').html(data.body.funcName)
      $('.topic-detail-count').html('已更新<span>' + data.body.articleCnt + '</span>篇')
      if (data.body.introduction) {
        $('.topic-detail-desc').html(data.body.introduction)
        $('.topic-detail-btn').html('查看更多')

        $('.topic-detail-btn').click(function () {
          Template.bottomPop(data.body.funcName, data.body.introduction)
        })
      }
    })
  }

  function getInfoListByFuncCode() {
    // 根据funcCode获取资讯列表
    Server.topicDetail.getInfoListByFuncCode({
      funcCode: pm.funcCode,
      lastDttm: pm.lastDttm,
      pageSize: pm.pageSize
    }).then(function (data) {
      let htmlStr = ''
      let len = 0
      if (data.body.list !== null) {
        len = data.body.list.length
        pm.stockList = []
        $.each(data.body.list, function (i, item) {
        //  console.log(item)
          //处理分隔线
          if (pm.pageNum > 1 || i >= 1) {
            htmlStr += '<div class=\'info-list-topborder\'></div>'
          }
          if (item.exhibitionMode === '2' && Utils.notEmpty(item.coverImgUrl)) {
            htmlStr += Template.dealBigImgInfo(item)
          } else {
            htmlStr += Template.dealInfo(item)
          }
        })
        if (pm.pageNum === 1) {
          $('.topic-detail-wrap').html(htmlStr)
        } else {
          $('.topic-detail-wrap').append(htmlStr)
        }
        Template.stockRise()
      }

      //记录下一次遍历的日期
      pm.lastDttm = data.body.lastDttm
      pm.pageNum ++
      meScroll.endSuccess(len, data.body.hasNextPage)

    }).catch((error) => {
      jsBridge.log(error)
      meScroll.endErr()
    })
  }

  //处理状态栏滚动效果
  function dealHead(scrollTop) {
    let currStop = 0
    if (scrollTop < 64) {
      currStop = scrollTop
      $('.center-bar').html('')
      $('.left-bar').css({
        'color': 'rgb(255,255,255)'
      })
    } else {
      currStop = 64
      $('.center-bar').html(pm.title)
      $('.left-bar').css({
        'color': 'rgba(34, 34, 34, ' + currStop / 64 + ')'
      })
    }
    $('.placeholder-top').css({
      'background': 'rgba(255, 255, 255, ' + currStop / 64 + ')'
    })

  }

  /**
   * @param callback 翻页回调函数
   */
  function pageScroll() {
    $('.mescroll').scroll(function () {
    //需要特殊处理的滚动区域，需要放在scroller元素区域内
      let scrollTop = $(this).scrollTop()
      dealHead(scrollTop)
    })
  }
</script>
</html>
